//简单的Node web服务器

//引入http模板
const http = require('http');

//创建一个server实例
const server = http.createServer();

//监听request事件

server.on('request',function(req,res){
	//console.log("已经接收到请求");
	const url = req.url;
	if(url == '/'){
		res.end("This is IndexPage");
	}else if(url == '/myblog'){
		res.end("This is MyBlogPage");
	}else if(url == '/mydata'){
		const animal = [
			{
				name:"pig",
				age: 1,
				weight: "200斤"
			},
			{
				name:"dog",
				age:3,
				weight: "70斤"
			}

		]
		res.end(JSON.stringify(animal));
	}
	else{
		res.end("This is ErrorPage");
	}
});

//绑定端口
server.listen('3000',function(){
	console.log("响应请求成功！请通过localhost:3000访问");
});